package com.tzraeq.quercus;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.servlet.ReadListener;
import javax.servlet.ServletInputStream;

public class StringServletInputStreamWrapper extends ServletInputStream {

	private InputStream is;
	
	public StringServletInputStreamWrapper(String str){
		is = new ByteArrayInputStream(str.getBytes());
	}
	
	public boolean isFinished() {
		int rest = 0;
		try {
			rest = is.available();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return 0==rest;
	}

	public boolean isReady() {
		
		return !isFinished();
	}

	public void setReadListener(ReadListener listener) {
		
	}

	public int read() throws IOException {
		return is.read();
	}
	
	public int read(byte[] buf, int off, int len) throws IOException {
		return is.read(buf, off, len);
	}

}
